﻿using SerialCommunication.Common;
using System.IO.Ports;

namespace SerialCommunication.Model
{
    public class SerialPortSetting : AppBase<SerialPortSetting>
    {
        private readonly NotificationOjbect _notification = new NotificationOjbect();

        public SerialPortSetting()
        {
            PortName = "COM1";
            BaudRate = 1200;
            DataBits = 8;
            Parity = Parity.None;
            StopBits = StopBits.One;
            StartChar = "=";
        }

        private string _PortName;
        /// <summary>
        /// 端口名称
        /// </summary>
        public string PortName
        {
            get { return _PortName; }
            set
            {
                _PortName = value;
                _notification.RaisePropertyChanged("PortName");
            }
        }
        private int _BaudRate;
        /// <summary>
        /// 波特率
        /// </summary>
        public int BaudRate
        {
            get { return _BaudRate; }
            set
            {
                _BaudRate = value;
                _notification.RaisePropertyChanged("BaudRate");
            }
        }
        private int _DataBits;
        /// <summary>
        /// 位数
        /// </summary>
        public int DataBits
        {
            get { return _DataBits; }
            set
            {
                _DataBits = value;
                _notification.RaisePropertyChanged("DataBits");
            }
        }
        private Parity _Parity;
        /// <summary>
        /// 奇偶
        /// </summary>
        public Parity Parity
        {
            get { return _Parity; }
            set
            {
                _Parity = value;
                _notification.RaisePropertyChanged("Parity");
            }
        }
        private StopBits _StopBits;
        /// <summary>
        /// 停止位
        /// </summary>
        public StopBits StopBits
        {
            get { return _StopBits; }
            set
            {
                _StopBits = value;
                _notification.RaisePropertyChanged("StopBits");
            }
        }
        private string _StartChar;
        /// <summary>
        /// 开始字符
        /// </summary>
        public string StartChar
        {
            get { return _StartChar; }
            set
            {
                _StartChar = value;
                _notification.RaisePropertyChanged("StartChar");
            }
        }
    }
}
